<?php
/**
 * AdminUserEdit.php
 *
 * This page is for admin to edit user's account information
 * such as their password, email address, etc.
 *
 * Written by: Siggles
 * Last Updated: December 26, 2011
 */

/**
 * User has submitted form without errors and user's
 * account has been edited successfully.
 */
if(isset($_SESSION['adminedit']))
{
   unset($_SESSION['adminedit']);
   echo 
"<div id=\"form_container\">
    <div id=\"title_container\">
        <div id=\"title\">
            <p>User Account Edit Success!</p>
        </div>
    </div>
	<div id=\"form_content\">
		<div id=\"form_text\"><b>".$_SESSION['usertoedit']."'s</b> account has been successfully updated.
		<br><br>Back to the <a href='../admin/main.php?id=3'>Admin Page</a>
		</div>
	</div>
</div>";
		unset($_SESSION['usertoedit']);
}
else
{

/**
 * If user is not logged in, then do not display anything.
 * If user is logged in, then display the form to edit
 * account information, with the current email address
 * already in the field.
 */
if(!$session->isAdmin()){
   // header("Location: ".$config['WEB_ROOT'].$config['home_page']);
   header("Location: ../index.php");
} else {
	if(!isset($_GET['usertoedit']))
	{?>
	<div id="form_container">
        <div id="title_container">
            <div id="title">
                <p>Invalid User Selection</p>
            </div>
        </div>
        <div id="form_content">
            <div id="form_text">Please select a user to edit</div>
        </div>
	</div>
<?php } else {
$usertoedit=$_GET['usertoedit'];
$req_user_info = $database->getUserInfo($usertoedit);
?>
<div id="form_container">
    <div id="title_container">
        <div id="title">
            <p>Admin User Account Edit : <?php echo $usertoedit; ?></p>
        </div>
        <div id="title_link">
            <p><a href="javascript:history.back(-1)">Back</a></p>
        </div>
    </div>
    <div id="form_content">
    	<?php if($form->num_errors > 0)
            { ?>
            <div id="form_error">
				<?php $form->num_errors ?> error(s) found
            </div>
		<?php } ?>
    <form action="adminprocess.php" method="POST">
        <ul>
            <li id="li_username">
            <label id="label_username" for="username">Username <?php echo $form->error("username"); ?></label>
            <input id="username" type="text" disabled="disabled" name="username" size="30" maxlength="30" 
            value="<?php if($form->value("username") == ""){ echo $req_user_info['username'];}else{echo $form->value("username");}?>" />
            </li>
            <li id="li_userlevel">
            <label id="label_userlevel" for="userlevel">User Level <?php echo $form->error("userlevel"); ?></label>
           	<input id="userlevel" name="userlevel" type="text" size="5" maxlength="10" 
            value="<?php if($form->value("userlevel") == ""){echo $req_user_info['userlevel'];}else{echo $form->value("userlevel");}?>" >
            </li>
            <!--<li id="li_newpass">
            <label id="label_newpass" for="newpass">Password <?php echo $form->error("newpass"); ?></label>
            <input id="newpass" name="newpass" disabled="disabled" type="password" size="30" maxlength="30"  value="<?php echo $form->value("newpass"); ?>" />
            </li>
            <li id="li_newpass2">
            <label id="label_newpass2" for="newpass2">Confirm Password <?php echo $form->error("newpass"); ?></label>
            <input id="newpass2" name="newpass" disabled="disabled" type="password" size="30" maxlength="30" value="<?php echo $form->value("newpass"); ?>" />
            </li>-->
            <li id="li_firstName">
            <label id="label_firstName" for="firstName">First Name</label>
            <input id="firstName" type="text" name="firstName" disabled size="30" maxlength="30" value="<?php echo $req_user_info['firstName'];?>" />
            </li>
            <li id="li_lastName">
            <label id="label_lastName" for="lastName">Last Name</label>
            <input id="lastName" type="text" name="lastName" disabled size="30" maxlength="30" value="<?php echo $req_user_info['lastName'];?>" />
            </li>
            <li id="li_email">
            <label id="label_email" for="email">Email <?php echo $form->error("email"); ?></label>
            <input id="email" name="email" type="text" disabled="disabled" size="30" maxlength="50"
            value="<?php if($form->value("email") == ""){echo $req_user_info['email'];}else{echo $form->value("email");}?>" >
            </li>
            <li id="li_phoneNumber">
            <label id="label_phoneNumber" for="phoneNumber">Phone Number</label>
            <input id="phoneNumber" type="text" name="phoneNumber" disabled placeholder="(___) ___-____ x._____" size="30" maxlength="30"
            value="(<?php echo $req_user_info['areaCode'];?>) <?php echo $req_user_info['prefix'];?>-<?php echo $req_user_info['lineNumber'];?> x.<?php echo $req_user_info['lineExt'];?>" />
            </li>
            <li id="li_about">
            <label id="label_about" for="about">About User</label>
            <textarea class="large" id="about" type="text" name="about" disabled value="<?php echo $req_user_info['about'];?>" /></textarea>
            </li>
            <li class="button">
                <input type="hidden" name="subedit" value="1">
                <input type="hidden" name="usertoedit" value="<?php echo $usertoedit; ?>">
                <input class="submit" type="submit" name="button" value="Edit Account">
                <input class="submit" type="submit" name="button" value="Delete" onclick="return confirm ('Are you sure you want to delete this user, this cannot be undone?\n\n' + 'Click OK to continue or Cancel to Abort!')">
            </li>
        </ul>
    </form>
    </div>
</div>
<!-- live typecasting -->
<script type="text/javascript" src="../jscripts/jquery.maskedinput-1.3.js" ></script>
<script>
jQuery(function($){
   $("#phoneNumber").mask("(###) ###-####? x.#####");
});
</script>
<?php
}}}
?>